﻿package com._public._display 
{
	import flash.display.BitmapData;
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.geom.Matrix;
	
	/**
	 * ...
	 * @author WZH(shch8.com) 2010-4-20 10:59
	 * 高光绘制 
	 * 可设置属性:
	 *  Highlights.ratios= [0x00, 0xFF];//渐变位置数组
		Highlights.colors= [0xffffff, 0xffffff];//渐变颜色数组
		Highlights.alphas= [0.1, 0.4];//渐变透明度数组
		例:
		Highlights.drawRoundRect(200,100,20,20)
	 */
	public class Highlights 
	{
		public static var ratios:Array = [0x00, 0xFF];//渐变位置数组
		public static var colors:Array = [0xffffff, 0xffffff];//渐变颜色数组
		public static var alphas:Array = [0.1, 0.4];//渐变透明度数组
		public static var gradient:int = 0;//渐变程度数值，值越大越接进消失点
		
		
		/**
		 * 三点取色法，判断图片右边沿色值
		 **/
		public static function threePointCol(bd:BitmapData):uint{
			var pickerPoint:Array = [1.2, 2, 4];
			var colAry:Array = [];
			for(var i:uint;i<3;i++){
				colAry.push(String(bd.getPixel(bd.width-pickerPoint[i],bd.height/pickerPoint[i])))
			}
			var col:uint = colAry[0];
			if(colAry[0].slice(0,1)==colAry[1].slice(0,1)&&colAry[0].length==colAry[1].length){
				col=colAry[0]
				}else if(colAry[0].slice(0,1)==colAry[2].slice(0,1)&&colAry[0].length==colAry[2].length){
					col=colAry[3]
					}else if(colAry[1].slice(0,1)==colAry[2].slice(0,1)&&colAry[1].length==colAry[2].length){
						col=colAry[2]
					}
			return col;
		}
		/**
		 * 绘制矩形高光
		 * @param	width			宽度
		 * @param	height			高度
		 * @param	ellipseWidth	宽圆角
		 * @param	ellipseHeight	高圆角
		 * @return 	Sprite
		 **/
		public static function drawRoundRect(width:uint,height:uint,ellipseWidth:uint=5,ellipseHeight:uint=5):Sprite
		{
			var shape:Shape = new Shape;
			var matr:Matrix = new Matrix();
			matr.createGradientBox(height-gradient, height-gradient);
			shape.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matr, SpreadMethod.PAD);  
			shape.graphics.drawRoundRect(1, 1, height,width,  ellipseWidth,ellipseHeight);
			shape.graphics.endFill();
			shape.rotation = -90;
			shape.y = height;
			var returnSpr:Sprite = new Sprite;
			returnSpr.mouseEnabled = false;
			returnSpr.addChild(shape);
			return returnSpr;
		}
		/**
		 * 绘制圆形高光
		 * @param	radius 圆半径
		 * @return	Sprite
		 */
		public static function drawCircle(radius:uint):Sprite
		{
		var shape:Shape = new Shape;
		var matr:Matrix = new Matrix();
		matr.createGradientBox(radius, radius);  
		shape.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matr, SpreadMethod.PAD);  
		shape.graphics.drawCircle(0,0,radius);
		shape.graphics.endFill();
		shape.rotation = -90;
		var returnSpr:Sprite = new Sprite;
		returnSpr.mouseEnabled = false;
		returnSpr.addChild(shape);
		return returnSpr;
		}
		/**
		 * 绘制椭圆高光
		 * @param	width	宽
		 * @param	height	高
		 * @return	Sprite
		 */
		public static function drawEllipse(width:uint,height:uint):Sprite
		{
		var shape:Shape = new Shape;
		var matr:Matrix = new Matrix();
		matr.createGradientBox(height, height);  
		shape.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matr, SpreadMethod.PAD);  
		shape.graphics.drawEllipse(0,0,height,width)
		shape.graphics.endFill();
		shape.rotation = -90;
		var returnSpr:Sprite = new Sprite;
		returnSpr.mouseEnabled = false;
		returnSpr.addChild(shape);
		return returnSpr;
		}	
	}
	
}